package com.cskaoyan.controller;

import com.cskaoyan.bean.goods.Comment;
import com.cskaoyan.bo.goods.GoodsPageAndSortBo;
import com.cskaoyan.service.goods.CommentService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.goods.CommentVo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:评论模块comment相关的controller层业务，主要功能有
 * list，即query
 * delete，浅删除
 * author:houzhitao@139.com
 */
@RestController
@RequestMapping("admin/comment")
public class CommentController {

    private ObjectMapper objectMapper = new ObjectMapper();
    {
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }

    @Autowired
    CommentService commentService;

    @RequestMapping("list")
    @RequiresPermissions("admin:comment:list")
    public BaseRespVo queryComment(GoodsPageAndSortBo pageAndSortBo){
        CommentVo commentVo = commentService.queryComment(pageAndSortBo);
        return BaseRespVo.ok(commentVo);
    }

    @RequestMapping("delete")
    @RequiresPermissions("admin:comment:delete")
    public BaseRespVo deleteComment(@RequestBody Comment comment){
        Integer effectNum = commentService.deleteComment(comment);
        if(effectNum==0){
            return BaseRespVo.error(401,"删除失败");
        }
        return BaseRespVo.ok();
    }

}
